package com.zhuoyi.security.service.location;

import android.content.pm.PackageInfo;
import android.os.RemoteException;
import android.util.Log;

public class LocationAgent {
	
	
	public static LocationAgent instance;
	
	private LoacationCallBack mCallBack;
	
	private LocationAgent(){
		
	}
	
	public static LocationAgent getInstance() {
		if(instance == null){
			instance = new LocationAgent();
		}
		return instance;
	}
	
	
	public void setCallback(ILocationSecurityService service,PackageInfo packageInfo,LoacationCallBack callBack) {
		try {
			service.listenUserEvent(mIDownListener.toString(), mIDownListener,packageInfo.packageName ,packageInfo.versionCode);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		mCallBack = callBack;
	}
	
	public void removeCallback(ILocationSecurityService service) {
		try {
			service.unregisterListener(mIDownListener.toString(), mIDownListener);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		mCallBack = null;
	}
	
	ILocationListener mIDownListener = new ILocationListener.Stub() {
				@Override
				public void getLocationStrByCooCompleted(String locationInfo)
						throws RemoteException {
					mCallBack.getLocationStrByCooCompleted(locationInfo);
				}

				@Override
				public void getLocationStrCompleted(String locationInfo)
						throws RemoteException {
					mCallBack.getLocationStrCompleted(locationInfo);
				}

				@Override
				public void getCoordinatesCompleted(String locationInfo)
						throws RemoteException {
					mCallBack.getCoordinatesCompleted(locationInfo);
				}
			};
   			
	public interface LoacationCallBack {
    	public void getLocationStrByCooCompleted(String locationInfo);
    	public void getLocationStrCompleted(String locationInfo);
    	public void getCoordinatesCompleted(String locationInfo);
    	
    }

}
